home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoTooluButton.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  6.0 KB  |  184 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2002 Werner Trobin <trobin@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.  * Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef _kotoolbutton_h_
  21. #define _kotoolbutton_h_
  22.  
  23. #include <ktoolbarbutton.h>
  24. #include <qmap.h>
  25. #include <qpoint.h>
  26.  
  27. class QPopupMenu;
  28.  
  29. class KoColorPanel : public QWidget
  30. {
  31.     Q_OBJECT
  32. public:
  33.     KoColorPanel( QWidget* parent = 0, const char* name = 0 );
  34.     virtual ~KoColorPanel();
  35.  
  36.     virtual QSize sizeHint() const;
  37.     virtual QSize minimumSizeHint() const;
  38.  
  39.     enum MenuStyle { Plain, CustomColors };
  40.     static QPopupMenu* createColorPopup( MenuStyle style, const QColor& defaultColor,
  41.                                          const QObject* receiver, const char* slot,
  42.                                          QWidget* parent, const char* name );
  43.  
  44. public slots:
  45.     void clear();
  46.     void insertColor( const QColor& color );
  47.     void insertColor( const QColor& color, const QString& toolTip );
  48.     void insertDefaultColors();
  49.  
  50. signals:
  51.     void colorSelected( const QColor& color );
  52.  
  53. protected:
  54.     virtual void mousePressEvent( QMouseEvent* e );
  55.     virtual void mouseReleaseEvent( QMouseEvent* e );
  56.     virtual void mouseMoveEvent( QMouseEvent* e );
  57.     virtual void paintEvent( QPaintEvent* e );
  58.     virtual void keyPressEvent( QKeyEvent* e );
  59.     virtual void focusInEvent( QFocusEvent* e );
  60.     virtual void dragEnterEvent( QDragEnterEvent* e );
  61.     virtual void dropEvent( QDropEvent* e );
  62.  
  63. private:
  64.     // The position of the 16x16 tiles in "tile steps"
  65.     struct Position {
  66.         Position() : x( -1 ), y( -1 ) {}
  67.         Position( short x_, short y_ ) : x( x_ ), y( y_ ) {}
  68.  
  69.         short x;
  70.         short y;
  71.     };
  72.     friend bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
  73.  
  74.     void finalizeInsertion( const Position& pos );
  75.     bool insertColor( const QColor& color, bool checking );
  76.     bool insertColor( const QColor& color, const QString& toolTip, bool checking );
  77.     bool isAvailable( const QColor& color );
  78.  
  79.     Position mapToPosition( const QPoint& point ) const;
  80.     QColor mapToColor( const QPoint& point ) const;
  81.     QColor mapToColor( const Position& position ) const;
  82.     QRect mapFromPosition( const Position& position ) const;
  83.     Position validPosition( const Position& position );
  84.  
  85.     int lines() const;
  86.     void paintArea( const QRect& rect, int& startRow, int& endRow, int& startCol, int& endCol ) const;
  87.     void updateFocusPosition( const Position& newPosition );
  88.     void paint( const Position& position );
  89.     void init();
  90.  
  91.     Position m_nextPosition, m_focusPosition;
  92.     QMap<Position, QColor> m_colorMap;
  93.     QPoint m_pressedPos;
  94.     bool m_defaultsAdded;
  95. };
  96.  
  97. // Needed for the use of KoColorPanel::Position in QMap
  98. bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
  99.  
  100.  
  101. // A tiny class needed to emit the correct signal when the default
  102. // color item in the color-panel popup is activated. Additionally
  103. // it's used to provide the color select dialog and manages the recent
  104. // colors... hacky
  105. class KoColorPopupProxy : public QObject
  106. {
  107.     Q_OBJECT
  108. public:
  109.     KoColorPopupProxy( const QColor& defaultColor, KoColorPanel* recentColors, QObject* parent, const char* name );
  110.     virtual ~KoColorPopupProxy() {}
  111.  
  112.     void setRecentColorPanel( KoColorPanel* recentColors );
  113.  
  114. public slots:
  115.     void slotDefaultColor();
  116.     void slotMoreColors();
  117.  
  118. signals:
  119.     void colorSelected( const QColor& color );
  120.  
  121. private:
  122.     QColor m_defaultColor;
  123.     KoColorPanel* m_recentColors;
  124. };
  125.  
  126.  
  127. // Parts of the code are from KToolBarButton
  128. class KoToolButton : public KToolBarButton
  129. {
  130.     Q_OBJECT
  131. public:
  132.     /**
  133.      * Construct a button with an icon loaded by the button itself.
  134.      * This will trust the button to load the correct icon with the
  135.      * correct size.
  136.      *
  137.      * @param icon   Name of icon to load (may be absolute or relative)
  138.      * @param id     Id of this button
  139.      * @param parent This button's parent
  140.      * @param name   This button's internal name
  141.      * @param txt    This button's text (in a tooltip or otherwise)
  142.      */
  143.     KoToolButton( const QString& icon, int id, QWidget* parent,
  144.                   const char* name = 0L, const QString& txt = QString::null,
  145.                   KInstance* _instance = KGlobal::instance() );
  146.  
  147.     /**
  148.      * Construct a button with an existing pixmap.  It is not
  149.      * recommended that you use this as the internal icon loading code
  150.      * will almost always get it "right".
  151.      *
  152.      * @param icon   Name of icon to load (may be absolute or relative)
  153.      * @param id     Id of this button
  154.      * @param parent This button's parent
  155.      * @param name   This button's internal name
  156.      * @param txt    This button's text (in a tooltip or otherwise)
  157.      */
  158.     KoToolButton( const QPixmap& pixmap, int id, QWidget* parent,
  159.                   const char* name = 0L, const QString& txt = QString::null );
  160.  
  161.     virtual ~KoToolButton();
  162.  
  163.     virtual QSize sizeHint() const;
  164.     virtual QSize minimumSizeHint() const;
  165.     virtual QSize minimumSize() const;
  166.  
  167. public slots:
  168.     void colorSelected( const QColor& color );
  169.  
  170. protected:
  171.     virtual void drawButton(QPainter *p);
  172.     virtual bool eventFilter( QObject* o, QEvent* e );
  173.  
  174. private:
  175.     void init();
  176.     void buttonShift( int& dx, int& dy );
  177.     bool hitArrow( const QPoint& pos );
  178.  
  179.     QPopupMenu* m_popup;
  180.     bool m_arrowPressed;
  181. };
  182.  
  183. #endif // _kotoolbutton_h_
  184.